import { UI_Layer, Control_Listen, RedDot_Key, UI_Listen } from '../../config/ui_def'
import { Sdk_Platform } from '../../frame/constants';

cc.Class({
    extends: cc.Component,

    properties: {
        share: cc.Node
    },

    // LIFE-CYCLE CALLBACKS:

    // update (dt) {},
    initPage() {
    },
    updatePage() {
        switch (common.sdk_env) {
            case Sdk_Platform.OPPO:
                this.share.active = false
                break
        }
        gg.eventManager.on('LeftBar', this.listenClient, this)
    },
    closeUI() {
        gg.eventManager.off("LeftBar", this.listenClient, this)
    },

    listenClient(code, param, arg) {
        if (code) {
            switch (code) {
                case Control_Listen.UPDATE_RED_DOT:
                    this.updateRed(param, arg)
                    break
            }
        }
    },

    updateRed(key, status) {
        let red_node
        switch (key) {
            case RedDot_Key.DAY_SIGN:
                red_node = this.node.getChildByName('Sign').getChildByName('red_dot')
                break;
        }
        red_node.active = status
    },

    activityServer() {

    },

    illustrateServer() {

    },

    rankServer() {

    },

    signServer() {
        he.voice.playEffect("button", "voice")
        gg.eventManager.emit('main', { type: UI_Listen.MAIN_NEWPAGE, pageName: 'signPage' })
        gg.uiManager.addPage(UI_Layer.Cover, {
            name: 'signPage',
            cover: true
        })
    },

    // activityServer() {
    //     he.voice.playEffect("button", "voice")
    //     gg.uiManager.addPage(UI_Layer.Cover, {
    //         name: 'manhuaPage',
    //         cover: true,
    //         cover_opacity: 240,
    //         episode: 0
    //     })
    // },

    shareServer() {
        // gg.uiManager.addTip('功能暂未')
        switch (common.sdk_env) {
            case Sdk_Platform.WECHAT:
                he.share.share()
                break
            case Sdk_Platform.VIVO:
                qg.share()
                break
            case Sdk_Platform.OPPO:

                break
            case Sdk_Platform.UC:
                uc.shareAppMessage({
                    query: '', // 查询字符串，必须是 key1=val1&key2=val2 的格式。
                    // 从这条转发消息进入后，可通过 uc.getLaunchOptionsSync() 获取启动参数中的 query。
                    target: 'wechat', // wechat:微信好友，qq: qq好友，不设置的话会调起分享面板
                    success: res => {
                        console.log('shareAppMessage share success', JSON.stringify(res));
                    },
                    fail: err => {
                        console.log('shareAppMessage share fail', JSON.stringify(err));
                    },
                });
                break
            default:
                gg.uiManager.addTip('本地你分享个锤子')
                break
        }
    },
});
